package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.ClientSendTalkDTO;
import com.yxw.live_vod_boot.dto.CreateSessionTalkDto;
import com.yxw.live_vod_boot.dto.PageSessionTalkDto;
import com.yxw.live_vod_boot.dto.PageTalkRecodesDto;
import com.yxw.live_vod_boot.service.SessionTalkService;
import com.yxw.live_vod_boot.vo.PageSessionTalkVo;
import com.yxw.live_vod_boot.vo.PageTalkRecodesVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author liuxin
 * 2023.12.04
 * 会话管理
 */
@RestController
@RequestMapping("/api/sessionTalk")
@Api(value = "会话管理", tags = "会话管理")
@Slf4j
public class SessionTalkController {

    @Autowired
    private SessionTalkService sessionTalkService;

    @PostMapping(value = "/pageSessionTalkList")
    @ApiOperation(value = "分页查询会话列表")
    public BaseResult<PageVO<PageSessionTalkVo>> pageSessionTalkList(@RequestBody PageSessionTalkDto dto){
        PageVO<PageSessionTalkVo> vo= sessionTalkService.pageSessionTalkList(dto);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @PostMapping(value = "/deleteSessionTalkById")
    @ApiOperation(value = "删除会话")
    public BaseResult deleteSessionTalkById(@RequestParam String talkId){
        sessionTalkService.deleteSessionTalkById(talkId);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @PostMapping(value = "/pageTalkRecordes")
    @ApiOperation(value = "分页查询会话记录列表")
    public BaseResult<PageVO<PageTalkRecodesVo>> pageTalkRecordes(@RequestBody @Validated PageTalkRecodesDto dto){
        PageVO<PageTalkRecodesVo> vo= sessionTalkService.pageTalkRecordes(dto);
        return BaseResult.doSuccess(vo,"查询成功");
    }
    @PostMapping(value = "/deleteTalkRecordeBYId")
    @ApiOperation(value = "删除会话记录（用于单方面删除会话）")
    public BaseResult deleteTalkRecordeBYId(@RequestParam Long recordId){
        sessionTalkService.deleteTalkRecordeBYId(recordId);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @PostMapping(value = "/recallMessage")
    @ApiOperation(value = "消息撤回")
    public BaseResult recallMessage(@RequestParam Long recordId){
        sessionTalkService.recallMessage(recordId);
        return BaseResult.doSuccess(null,"撤回成功");
    }

    @PostMapping(value = "/createSessionTalk")
    @ApiOperation(value = "创建会话")
    public BaseResult createSessionTalk(@RequestBody @Validated CreateSessionTalkDto dto){
        String sessionId=sessionTalkService.createSessionTalk(dto);
        return BaseResult.doSuccess(sessionId,"创建成功");
    }


    @PostMapping(value = "/sendTalk")
    @ApiOperation(value = "发送会话")
    public BaseResult sendTalk(ClientSendTalkDTO dto,MultipartFile file){
        sessionTalkService.sendTalk(dto,file);
        return BaseResult.doSuccess(null,"发送成功");
    }


    @PostMapping(value = "/updateReadStatus")
    @ApiOperation(value = "消息从未读变已读")
    public BaseResult updateReadStatus(@RequestParam String sessionId){
        sessionTalkService.updateReadStatus(sessionId);
        return BaseResult.doSuccess(null,"操作成功");
    }
}
